home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / aaem95ma.zip / EM.H < prev    next >
C/C++ Source or Header  |  1995-03-05  |  33KB  |  700 lines

  1. /* This file is EM.H */
  2. #define VERSION "5 Mar 1995"
  3. /* also update the date at start of README & README.1ST */
  4. #include <std.h>
  5. #include <setjmp.h>
  6. #include <string.h>
  7. #include <ctype.h>
  8. #include <new.h>
  9. #include <pc.h>
  10. #include <dpmi.h>
  11. #include <time.h>
  12. /*-----*/
  13. #define uns unsigned
  14. #define reg register
  15. enum{strsize=1024}; /* must be multiple of 8 */
  16. #define lwand(n) ((n+7)/8) /* wand = bit pattern of which chars are magic */
  17. #define lmagic(n) (((((n)&0x00ffffff)*9+7)>>3)+1) /* length of string+1+wand */
  18. enum{magicsize=lmagic(strsize)};
  19. enum{LF=10,CR=13,esc=27}; /* C '\n' == LF, but PC RET key = CR */
  20. /*-----*/
  21. extern void bitpack(char*s,char*t,int n);
  22. extern void showmoan();
  23. extern volatile void MOAN(char *m);
  24. typedef uns char byte;
  25. extern char CW[strsize],disp[256]; extern jmp_buf *bad,rep;
  26. extern void int10(); extern void int16(); extern void int21();
  27. extern void int33();
  28. /*-----*/
  29. #define namebit(name,member,bit) \
  30.   inline int name(){return (member>>bit)&1;}; \
  31.   inline void name(reg int i){if(i) member|=(1<<bit); else member&=~(1<<bit);};
  32. /*-----*/
  33. class buffer; class line; class mark; class gp_cur; class region; class macro;
  34. class keyarray; class parsing; class val; class colreg; class var; class Mouse;
  35. struct call_;
  36. typedef void subr(val,val,val); typedef val func(int,val*);
  37. class Subr{public: subr*f; short n,menur,menuc; char*name; short*args;};
  38. class Func{public: func*f; short n,menur,menuc; char*name; short*args;};
  39. /*-----*/
  40. inline int bit(char*s,int i) {return (s[i>>3]>>(7-(i&7)))&1;}
  41. /*-----*/
  42. enum {_typeend=3,_adinf=3,_magic=2,_string=1,_unbound=0,_subr=-1,_macro=-2,
  43.   _char=-3,_keyarray=-4,_buffer=-5,_int=-6,_keyseq=-7,_rsvword=-8,_unidfname=-9,
  44.   _call=-10,_bad=-11,_Subr=-12,_func=-13,_Func=-14,_ref=-15,_type=-16,
  45.   _float=-17,_label=-18,_typebeg=-18};
  46. /* code numbers of types. n>0 (and n==0 if s!=0) == string of n chars */
  47. extern char**keysort;
  48. /*----- a value and what type it is  */
  49. class val{public: int n; /* n == ditto, or +ve = string of n chars */
  50.   union{keyarray*k; subr*f; macro*m; char*s; buffer*b; int i; struct call_*C;
  51.     Subr*S; func*fn; Func*Fn; var*v; float x;};
  52. /* n      2nd field use
  53. >0        char*s         -> a string of n chars
  54.   0  unbound   char*s         if s==0 or 1, nothing, else empty string
  55.  -1  _subr     subr*f         -> a function void ....(val,val,val)
  56.  -2  _macro    macro*m        -> a macro
  57.  -3  _char     int i          the char i. 256-511 mean 'alt/special key i&255'
  58.  -4  _keyarray keyarray*k     -> an array of val's corresponding to key values
  59.  -5  _buffer   buffer*b  -> a buffer
  60.  -6  _int      int i          the integer i
  61.  -7  _keyseq   char*s         -> a keysequence,kept in chars s[1] to s[s[0]-1]
  62.  -8  _rsvword  int i          the i'th reserved_word
  63.  -9  _unidfname     char*s         -> an unidentified word (terminated by '\000')
  64. -10  _call     struct call_*C -> base & args of a function call
  65. -11  _bad char*s         -> a string describing what was wrong
  66. -12  _Subr     Subr*S         -> an entry in the table of subr names & info
  67. -13  _func     func*fn        -> a function val ....(int,val*)
  68. -14  _Func     Func*Fn        -> an enter in the table of func names & info
  69. -15  _ref var*v          a variable
  70. -16  _type     int i          the name of the type i
  71. -17  _float    float x        the float x
  72. -18  _label       (will only occur in var's)
  73. 0x80000000+n   char*s         -> a magic string of n chars */
  74. inline val(val&K){n=K.n; s=K.s;}; /* works, as all 2nd members are 4 bytes */
  75. inline val(){s=0; n=0;}; /* binding key to each allowed type:- */
  76. inline val(buffer*B){b=B; n=_buffer;}
  77. inline val(float X){x=X; n=_float;};
  78. inline val(char C){i=C; n=_char;};
  79. inline val(byte C){i=C; n=_char;};
  80. inline val(char*S,int t){s=S; n=t;};
  81. inline val(char*t){n=strlen(s=t);};
  82. inline val(int I,int t=_int){i=I; n=t;};
  83. inline val(keyarray&K){k=&K; n=_keyarray;};
  84. inline val(macro*M){m=M; n=_macro;};
  85. inline val(struct call_*I){C=I; n=_call;};
  86. /* inline val(subr*F){f=F; n=_subr;}; */
  87. inline val(Subr*B){S=B; n=_Subr;};
  88. /* inline val(func*F){fn=F; n=_func;}; */
  89. inline val(Func*B){Fn=B; n=_Func;};
  90. inline val(var*V){v=V; n=_ref;};
  91. inline int magic(){return (n&0xff000000)==0x80000000;};
  92. inline int magic(int i){return bit(s+(n&0x00ffffff)+1,i);};
  93. inline int bad(){return n==_bad;};
  94.  
  95. inline void operator=(buffer*B){b=B; n=_buffer;};
  96. inline void operator=(byte C){i=C; n=_char;};
  97. inline void operator=(char C){i=C; n=_char;};
  98. inline void operator=(char*t){n=strlen(s=t);};
  99. inline void operator=(int I){i=I; n=_int;};
  100. inline void operator=(keyarray&K){k=&K; n=_keyarray;};
  101. inline void operator=(macro&M){m=&M; n=_macro;};
  102. inline void operator=(struct call_*I){C=I; n=_call;};
  103. inline void operator=(const val&t){s=t.s; n=t.n;};
  104. inline void operator=(subr*F){f=F; n=_subr;};
  105. inline int operator<<(int j){return n!=_rsvword?0:i==j;};
  106. inline int operator==(byte C){return n!=_char?0:i==C;};
  107. inline int operator==(subr*F){return n!=_subr?0:f==F;};
  108. inline int operator==(val&F){return F.n==n?F.s==s:0;};
  109. inline int notstring(){return n<0?1:n>0?0:!s;}
  110. int operator==(char*t);
  111. inline val operator-(){return val(-i,_int);}; /* only use with _int's */
  112. char*moanifbound(val K,int jump=1);
  113. Subr*Subrinfo(); char*Subrname();
  114. Func*Funcinfo(); char*Funcname();
  115. int charval();
  116. int operator>>(char c); /* char in string? */
  117. int checktype(int type); val convto(int type);
  118. val copy();
  119. val&keyseq();
  120. val&operator[](int N);
  121. void del();
  122. void expandkeyseq(char*K,int plain=0); /* expand char* into names of keys */
  123. val getifn(val&T,char*prompt,int type=0,char*start=0);
  124. val operator()(); /* obey the val */
  125. int type();
  126. int typ();
  127. void print(char*Z=(char*)_buffer,int pr=1000);
  128. void subarray();
  129. void unbind();
  130. int known_now();         };
  131. inline int ScreenRows() {return *(unsigned char*)0xe0000484+1;}
  132. inline int ScreenCols() {return *(unsigned short*)0xe000044a;}
  133. inline int ScreenMode() {return *(unsigned char*)0xe0000449;}
  134. /*-----*/
  135. inline val kf(subr*F){val f; f.f =F; f.n=_subr; return f;};
  136. inline val ff(func*F){val f; f.fn=F; f.n=_func; return f;};
  137. extern char*copyof(char*s,int n=0);
  138. extern char*copyof(const val&s);
  139. extern char*chname(int c);
  140. extern char*keyname(int c,int alt=0);
  141. extern void Obey(val N=val(1,0));
  142. extern int yesno(char*pt); extern int Yesno(char*s);
  143. /*----- standard header for key-functions */
  144. #define KF(name) void name(val N/*=val(1,0)*/,val T1/*=val()*/,val T2/*=val()*/)
  145. #define Kf(name) extern void name(val N=val(1,0),val T1=val(),val T2=val())
  146. /* if N.n!=0, N.i==repeat count, usually */
  147. #define FN(name) val name(int n,val*arg)
  148. #define fN(name) extern FN(name)
  149. /*----- a detached chain of lines */
  150. class Text{public: line *beg,*end;
  151. inline Text(){beg=end=0;};
  152. inline Text(line*b,line*e){beg=b; end=e;}
  153. inline Text(Text&T){beg=T.beg; end=T.end;};
  154. inline operator=(const Text&T){beg=T.beg; end=T.end;};
  155. Text(val&); void read(char*file); Text copy(); void clear(); /*void print();*/};
  156. /*-----*/
  157. extern Text killring[]; extern short nkill;
  158. /*----- row and column on screen */
  159. class gp_cur{public: byte c,r;
  160.   inline gp_cur(byte R=0, byte C=0){c=C; r=R;};
  161.   inline gp_cur(gp_cur &d){c=d.c; r=d.r;};
  162.   inline void operator=(gp_cur&d){c=d.c; r=d.r;};};
  163. /*-----*/
  164. extern gp_cur cursor; /* the cursor */
  165. extern char *Moan,*Display;
  166. /*----- a position in buffer by line & char */
  167. class mark {public: mark *next,*prev; line *r; short c;
  168. inline mark(line*R=0,short C=0){r=R; c=C;};
  169. inline mark(const mark&m){r=m.r; c=m.c;};
  170. inline void operator=(const mark&m){r=m.r; c=m.c;};
  171. byte operator*(); /* char at mark */
  172. /* move mark 1 char *//* if runs off file, leaves this->r==0 :- */
  173. void operator++(); void operator--();
  174. void operator=(char);
  175. void operator+=(char); void operator+=(char*); void operator+=(buffer*);
  176. line* operator/(int);
  177. void operator!();
  178. void bs();
  179. operator char*();
  180. region yank(const Text&K,int copy=1);
  181. void operator>>=(int n);
  182. void operator<<=(int n);
  183. int Up(); int Down(); int Left(); int Right();
  184. int is_white(); int is_alpha(); int is_alnum();
  185. void find_white(int back=0); void skip_white(int back=0,int Eol=0);
  186. void skip_alpha(int back=0); void find_alpha(int back=0,int Eol=0);
  187. void skip_alnum(int back=0); void find_alnum(int back=0,int Eol=0);
  188. int eol(); int eof(); void Skip();
  189. void skipword(int); int isin(region &R);
  190. int operator<(mark&N);   /* are marks in that order? */
  191. inline int operator==(const mark&N){if(r==N.r) if(c==N.c) return 1; return 0;};
  192. inline int operator!=(const mark&N){if(r==N.r) if(c==N.c) return 0; return 1;};
  193. friend region operator-=(const mark&M,const mark&N);
  194. friend region operator-(const mark&M,const mark&N);
  195. inline friend void operator^(mark&M,mark&N){M.next=&N; N.prev=&M;};
  196. void push(); void hsup(); void pop();
  197. void skipsentence(int); void skippara(int);
  198. int thisch(char C); int string(val s); /* parsing:- */
  199. val elem(); /* P.elem() : look for an element, move P over text parsed */
  200. val name(); val label(); val number(); val string(); val expr(int prio=0);
  201. val monexpr_upto(int); val Call(); val decl();
  202. char*op(int);};
  203. extern int heremagic(mark A,val T);
  204. extern int here(mark A,val T,int w=0);
  205. /*----- two marks */
  206. class region{public: mark beg,end;
  207. inline region(){beg=mark(0,0); end=mark(0,0);};
  208. inline region(const mark &B,const mark &E){beg=B; end=E;};
  209. inline void operator=(const region&R){beg=R.beg; end=R.end;};
  210. mark Delete(int query=1); mark kill(int query=1); void copykill();
  211. void format();
  212. int huntf(val T,int word=0); int huntb(val T,int word=0);
  213. inline int hunt(val T,int back=0,int w=0){return back?huntb(T,w):huntf(T,w);};
  214. void replace(val Old,val New,int ask=0,int word=0);
  215. region moveto(mark &M); region copyto(mark &M); region repl(Text&k,int copy=1);
  216. void right_order(); void color(int f,int b); void Case(int);
  217. int ok_to_delete(); void expandtabs(); void maketabs(); };
  218. /*----- M-=N == the region defined by the marks M & N */
  219. inline region operator-=(const mark&M,const mark&N){return region(M,N);}
  220. /*----- ditto, make sure that M <= N */
  221. inline region operator-(const mark&M,const mark&N){
  222. region R(M,N); R.right_order(); return R;}
  223. /*----- a line in a buffer */
  224. class line {public:
  225.     line *next; /* -> the next line */
  226.     line *prev; /* -> the previous line */
  227.     short n; /* chars in line */
  228.     char *s; /* the line, physically has (n+15)&~15 bytes */
  229.     char info;
  230.     short sl; /* current screen line number (line_notshown == not on screen) */
  231. namebit(la,info,0); /* if line altered since last displayed */
  232. namebit(no_cr,info,1) /* if no CR before LF at end of this line */
  233. #define line_notshown 0x4000
  234. inline void nullline(){next=prev=0; s=0; n=0; info=0; la(1); sl=line_notshown;};
  235. inline line(){nullline();}; /* empty line */
  236. line(char*s); line(char*s,int n); line(line*L); ~line();
  237. void operator-(); /* remove previous eol */
  238. void operator--(); /* remove next eol */
  239. void operator-(Text&); /* remove next eol, in a Text */
  240. void display(int i); int dispfold(int i); int nparts(int c=-1); int showeol();
  241. friend inline void operator-(reg line &A,reg line &B){A.next=&B; B.prev=&A;};
  242.   /* link lines A and B */
  243. friend line* operator/ (line &L,val t); /* insert line after line L */
  244. friend line* operator/ (val t,line &L); /* insert line before line L */
  245. void operator= (val t);  /* replace text of line */
  246. void operator+=(char c); /* append char to line */
  247. void operator+=(line &M); /* append text of M to line */
  248. void operator= (int n);  /* change line.n */
  249. void operator+=(int n); void operator-=(int n);   /* ditto */
  250. char operator[](int n);  /* nth char in line */
  251. void empty();  /* delete all text in line */
  252. int to_tabexp(int,int=0); int from_tabexp(int,int=0);
  253. int to_scrcolno(int); /* char # to screen col # */
  254. int from_scrcolno(int); /* screen col # to char # */
  255. int blank(); /* if line is blank */
  256. void dotty();  /* check dot.c */
  257. void split_if_long(); void de_trailing_space();
  258. int is_bop(); int is_eop(); int lineno(); void del(); };
  259. /*-----*/
  260. extern line*dustbin; extern void emptydustbin();
  261. extern line *line0,*modeline; /* dummy lines */
  262. inline byte mark::operator*(){return c>=r->n?LF:r->s[c];} /* char at mark */
  263. inline int mark::eol(){return c>=r->n;}
  264. inline int mark::eof(){return r->next?0:c>=r->n;}
  265. inline void mark::operator++(){if(++c>r->n) {c=0; r=r->next;}}
  266. inline void mark::operator--(){if(--c<0) c=(r=r->prev)?r->n:0;}
  267. /*-----*/
  268. class screenline{public:line *l,*nl; int lp,nlp,np,lc,ok,nc; uns short*sa;
  269.   buffer*buf;};
  270. /*-----*/
  271. extern screenline Sl[];
  272. /*----- text to be displayed colored */
  273. class colreg {public: int fg,bg; region Reg;
  274. inline init() {fg=bg=0; Reg.beg=mark(0,0); Reg.end=mark(0,0);};
  275. inline colreg() {init();};};
  276. /*** I must keep track of these marks on any text changes */
  277. /*-----*/
  278. class buffer {public:
  279.     buffer *next;   /* next buffer */
  280.     mark start; /* -> top left char on screen */
  281.     int startc; /* backup for start.c */
  282.     int stback;     /* if fold long lines, where in start.r to start */
  283.     mark dot;  /* cursor */   /* start of chain of marks */
  284.     mark olddot;     /* where dot was at start of current mouse operations */
  285.     mark dot1,dot2; /* where dot was before last command */
  286.     byte row1; /* first row of screen used by buffer */
  287.     byte lastrow;   /* last row of screen used by buffer */
  288.     byte nrows;     /* # of rows of text on screen incl. info line */
  289.     byte ncols;     /* # of cols of text on screen */
  290.     short dotcc,dotcc2;  /* screen col # of dot */
  291.     line text; /* completes circle of lines */
  292.     byte truncated,invisible,readonly,changed,oldch,refresh; /* flags */
  293.     byte overlay,tabtype,twod,wrap,Case,longlines,skip_after_word; /* modes */
  294. #define buffer_nmodes 7
  295.     int rmargin,sortcol;
  296.     char *name;     /* file name */ val bound;
  297.     colreg col;
  298. void initbuffer(); inline buffer(){initbuffer();};
  299. buffer(char*F,int rd=1); /* new buffer opened on file F */
  300. ~buffer();
  301. line* operator[](int);   /* ith line in buffer */
  302. void deltext(); buffer*linkin();
  303. void read(); void write(); void clearscreen();
  304. void go_to(); void operator()(int N=0);
  305. inline mark bof(){return mark(text.next,0);};
  306. inline mark eof(){return mark(text.prev,text.prev->n);};
  307. int nmarks(); mark&Mark(int); void display(); void dispfold(int d=0);
  308. void rem1mark(); void up(); void down(); void left(); void right();
  309. void split_window_with(int N);
  310. inline void operator+=(char c){dot+=c;}; /* insert at dot */
  311. inline void operator+=(char*s){dot+=s;}; /* insert at dot */
  312. void redraw_info(); int exists(); void bind(val*f,val T1);  };
  313. /*-----*/
  314. extern buffer *buf0, *bhead, *B; extern int bcount; /* B -> current buffer */
  315. extern line *T;     /* entry point of circle of lines currently being handled */
  316. /*-----*/
  317. #define forallbufs(b) for(b=bhead;b;b=b->next)
  318. #define forallmarks(M) for(M=&B->start;M;M=M->next)
  319. /* buffer has extra final empty line unless last char in file is not LF */
  320. /*-----*/
  321. extern char DIR[];
  322. #define HELPFILE "HELP"
  323. #define BIGHELPFILE "HELP.BIG"
  324. #define DICTFILE "DICT"
  325. extern char helpfile[],bighelpfile[],**infohelp,**infobig;
  326. extern char**Subrhelp(char*name);
  327. /*-----*/
  328. extern char T1w[],T2w[],Filename[]; extern val T1t,T2t,Fn,specialchars;
  329. extern int needswrap;
  330. enum {ob_kill=1,ob_yank,ob_other};
  331. extern int obtype,prevobtype; extern region lastyank;
  332. extern buffer*window[]; extern int nwindows,currentwindow;
  333. extern long _ax,_bx,_cx,_dx,_si,_di,_bp,_es; extern short _flags;
  334. #define _carry (_flags&1)
  335. #define _zeroflag (_flags&0x40)
  336. /*-----*/
  337. #define __SR() /* save the registers */         ({asm("xchgl %eax,__ax"); \
  338.     asm("xchgl %ebx,__bx"); asm("xchgl %ecx,__cx"); asm("xchgl %edx,__dx"); \
  339.     asm("xchgl %esi,__si"); asm("xchgl %edi,__di"); asm("xchgl %ebp,__bp"); })
  340. #define __RR() /* restore the registers */      ({ \
  341.     asm("pushf"); asm("popw __flags"); __SR();})
  342. /*-----*/
  343. enum Color{Black=0,Blue=1,Green=2,Cyan=3,Red=4,Magenta=5,Orange=6,White=7};
  344. /*-----*/
  345. extern byte gp_Mode,gp_Rows,gp_Cols;
  346. extern short gp_Attr,gp_Attr_def; /* on black */
  347. inline uns short sch(byte C,byte A){return C|(A<<8);}
  348. #define screen ((uns short*)ScreenPrimary)
  349. #define scr(row,col) (screen[(col)+(row)*gp_Cols])
  350. extern int getkey();
  351. extern int get_key(); extern int nextch;
  352. extern byte get__key();
  353. extern int getkey_nowait();
  354. extern int typahead();
  355. extern int inject(int ch);
  356. extern void printch(char c);
  357. extern int beep();
  358. extern int gp_mode(void);
  359. extern void gp_mode(char m);
  360. extern void gp_cursor(gp_cur c);
  361. inline void gp_cursor(int r,int c) {gp_cursor(gp_cur(r,c));}
  362. extern gp_cur gp_cursor(void);
  363. extern void gp_clear(int i=0,int j=0,int J=gp_Cols-1);
  364. /*-----*/
  365. /* the attribute of a displayed character: bc,fc = back- & foreground colors */
  366. /* fc add 8 for bright; */
  367. inline short Attrib(int fc,int bc=Black,int flash=0) {
  368.     return ((fc&15)<<0)|((bc&7)<<4)|((flash&1)<<7);}
  369. /* typedef struct {int fc:3, bright:1, bc:3, blink:1; } gp_Attrib; */
  370. /*-----*/
  371. /*** special keys. Some of these may be different on different PC's ****/
  372. enum {alt_0=129, alt_1=120, alt_2=121, alt_3=122, alt_4=123, alt_5=124,
  373. alt_6=125, alt_7=126, alt_8=127, alt_9=128, alt_A=30, alt_B=48, alt_C=46,
  374. alt_D=32, alt_E=18, alt_F=33, alt_G=34, alt_H=35, alt_I=23, alt_J=36, alt_K=37,
  375. alt_L=38, alt_M=50, alt_N=49, alt_O=24, alt_P=25, alt_Q=16, alt_R=19, alt_S=31,
  376. alt_T=20, alt_U=22, alt_V=47, alt_W=17, alt_X=45, alt_Y=21, alt_Z=44,
  377. alt_apostr=40, alt_bksp=14, alt_comma=51, alt_del=163, alt_downarrow=160,
  378. alt_end=159, alt_equals=131, alt_esc=1, alt_f10=113, alt_f11=139, alt_f12=140,
  379. alt_f1=104, alt_f2=105, alt_f3=106, alt_f4=107, alt_f5=108, alt_f6=109,
  380. alt_f7=110, alt_f8=111, alt_f9=112, alt_fullstop=5, alt_grave=41, alt_home=151,
  381. alt_insert=162, alt_leftarrow=155, alt_leftsq=26, alt_minus=130,
  382. alt_padminus=74, alt_padplus=78, alt_padslash=164, alt_padstar=55,
  383. alt_pagedown=161, alt_pageup=153, alt_ret=28, alt_rightarrow=157,
  384. alt_rightsq=27, alt_semicolon=39, alt_sharp=43, alt_slash=53, alt_tab=165,
  385. alt_uparrow=152, ctrl_2=3, ctrl_del=147, ctrl_downarrow=145, ctrl_end=117,
  386. ctrl_f10=103, ctrl_f11=137, ctrl_f12=138, ctrl_f1=94, ctrl_f2=95, ctrl_f3=96,
  387. ctrl_f4=97, ctrl_f5=98, ctrl_f6=99, ctrl_f7=100, ctrl_f8=101, ctrl_f9=102,
  388. ctrl_home=119, ctrl_insert=146, ctrl_leftarrow=115, ctrl_pad5=143,
  389. ctrl_padminus=142, ctrl_padplus=144, ctrl_padslash=149, ctrl_padstar=150,
  390. ctrl_pagedown=118, ctrl_pageup=132, ctrl_rightarrow=116, ctrl_tab=148,
  391. ctrl_uparrow=141, del=83, downarrow=80, end=79, f10=68, f11=133, f12=134, f1=59,
  392. f2=60, f3=61, f4=62, f5=63, f6=64, f7=65, f8=66, f9=67, home=71, ins=82,
  393. leftarrow=75, pad5=76, pagedown=81, pageup=73, rightarrow=77, sh_f10=93,
  394. sh_f11=135, sh_f12=136, sh_f1=84, sh_f2=85, sh_f3=86, sh_f4=87, sh_f5=88,
  395. sh_f6=89, sh_f7=90, sh_f8=91, sh_f9=92, sh_tab=15, uparrow=72, lbutton=255,
  396. mbutton=254, rbutton=253, lbuttond=252, mbuttond=251, rbuttond=250,
  397. mousemove=249};
  398. /*-----*/
  399. extern char *altnames[256],*altshortnames[256]; extern val keynames[];
  400. extern char* fullfilename(char*full,char*name);
  401. /*-----*/
  402. inline int bytes(char*s){return *(int*)s;}
  403. /*----- to next multiple of 16 */
  404. inline uns int roundup(uns int i) {return ((i)+15)&((uns int)0xfffffff0);}
  405. /*----- copy n chars from t to s */
  406. extern char* Copytext(char*s,char*t,int n);
  407. /* extern char* copy_text(char*s,char*t,int n); */
  408. /*-----*/
  409. /* {
  410. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0e,0x0f,
  411. 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1e,0x1f,
  412. 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2e,0x2f,
  413. 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3e,0x3f,
  414. 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4e,0x4f,
  415. 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5e,0x5f,
  416. 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6e,0x6f,
  417. 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7e,0x7f,
  418. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8e,0x8f,
  419. 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9e,0x9f,
  420. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xae,0xaf,
  421. 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbe,0xbf,
  422. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xce,0xcf,
  423. 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xde,0xdf,
  424. 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xee,0xef,
  425. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfe,0xff}; */
  426. /*----- compare n chars from t to s */
  427. int comptext(reg char*s,reg char*t,int n,int nocase=0);
  428. /*-----*/
  429. #define add_to_list(head,item) ((item)->next=(head), (head)=(item))
  430. #define remove_from_list(head,item) ({typeof(item) *I; \
  431.     for(I=&(head);*I;I=&((*I)->next)) if(*I==(item)) {*I=(*I)->next; break;}})
  432. /*-----*/
  433. /*** make fault remarks without mallocking, in case fault was 'out of store' */
  434. /*----- change color of jth char of ith screen line */
  435. extern void recolor(int i,int j,int col);
  436. /*----- display string s on screen line n (displayn = do not clear to eol) */
  437. extern int displayn(val  T,int n,int c,int fc=White,int bc=Black);
  438. extern int displayn(char*s,int n,int c,int fc=White,int bc=Black);
  439. extern void display(val  T,int n,int c,int fc=White,int bc=Black);
  440. extern void display(char*s,int n,int c,int fc=White,int bc=Black);
  441. extern void clearscreen();
  442. extern void getstring(char*pt,int Sl,val &T,int max,int type=0);
  443. /*-----*/
  444. extern char chwidth[256];
  445. extern byte to__upper[256],to__lower[256]; extern char chtype[256];
  446. enum{c_alpha=1,c_alnum=2,c_white=4};
  447. /*-----*/
  448. #define to_upper(c) to__upper[(byte)(c)]
  449. #define to_lower(c) to__lower[(byte)(c)]
  450. /*----- x==y ignoring case? */
  451. #define cheq(x,y,Case) (Case?((x)==(y)):to_upper(x)==to_upper(y))
  452. #undef iswhite
  453. #undef isalpha
  454. #undef isalnum
  455. #define iswhite(c) (chtype[(byte)(c)]&c_white)
  456. #define isalpha(c) (chtype[(byte)(c)]&c_alpha)
  457. #define isalnum(c) (chtype[(byte)(c)]&c_alnum)
  458. inline int mark::is_white(){return iswhite(c>=r->n?LF:r->s[c]);}
  459. inline int mark::is_alpha(){return isalpha(c>=r->n?LF:r->s[c]);}
  460. inline int mark::is_alnum(){return isalnum(c>=r->n?LF:r->s[c]);}
  461. /*-----*/
  462. extern region Found;
  463. /*-----*/
  464. typedef struct call_{char n,pr,*name; int type; val arg[1];} call;
  465. extern call*call_n(int n,int type,int pr,char*name,val*a);
  466. /*----- array of n key bindings to look up in */
  467. class keyarray {public:val*a; long n;   void subarray();
  468. inline keyarray(){a=0; n=0;}; val&operator[](int i);
  469. void search(void(*fn)(val&k));
  470. void print(int N=1,int i=1,int deep=1);      };
  471. /*-----*/
  472. extern val key0; extern keyarray keys; /* head of lookup tree of key bindings */
  473. /*----- one statement in a macro. Contains keybinding and numeric arg */
  474. class macstep{public: macstep *next; val f,N,T1,T2; /* like a call of a subr */
  475. inline macstep(val k=val(),val n=val(1,0),val t1=val(),val t2=val()){
  476.     f=k; N=n; next=0; T1=t1; T2=t2; next=0;};
  477. inline void operator=(macstep &m){f=m.f; N=m.N; T1=m.T1; T2=m.T2;}
  478. inline        macstep(macstep &m){f=m.f; N=m.N; T1=m.T1; T2=m.T2;}
  479. void operator()(int n=1); /* obey */
  480. void print(); /* print macstep into buffer text */
  481. void del(); macstep*copy();
  482. inline void clear(){f.n=T1.n=T2.n=0; N=val(1,0); f.s=T1.s=T2.s=0;};
  483. inline ~macstep(){del();}     };
  484. extern macstep laststep,thisstep;
  485. inline macstep*macstep::copy(){return new macstep(f,N,T1.copy(),T2.copy());};
  486. #define setrec(x,y) ({if(!play) thisstep.x=(y);})
  487. #define setrek(x,y) ({if(!play) thisstep.x=val(y);})
  488. #define setref(x,y) ({if(!play) thisstep.x=kf(y);})
  489. /*-----*/ /* offset+=0x80000000 if global */
  490. class var{public: var*next; char*name; long int type,offset;
  491. inline var(char*Name,int Type,int Offset,var*Next=0){
  492.     name=copyof(Name); type=Type; offset=Offset; next=Next;};
  493. inline ~var(){delete name; if(next) delete next;};};
  494. extern var*globvars; extern int nglobvars;
  495. void prvars(var*v);
  496. /*----- macro header */
  497. extern macro *record,*Macro,*macros;
  498. class macro{public: macstep *last,*text; val bound; macro*next; char*name;
  499. int nvars; var*vars;
  500. inline val&f(){return *(val*)&last;};
  501. inline macro(){last=text=0; bound=val(); next=macros; macros=this; name=0;
  502.     nvars=0; vars=0;};
  503. void operator+=(macstep*m);   /* append step to macro */
  504. void operator()(val N=val(1,0),int r=0); /* obey, arg=N, r = recursion depth */
  505. void print();  /* print macro on buffer text */
  506. void tidy();   /* e.g. chain up successive insert-a-character's */
  507. void empty(); ~macro();  };
  508. extern int macdepth; extern char*CMN; extern macstep _lazy;
  509. /*-----*/
  510. class macrinfo{public: macstep*prevstep; val*stack; int nvars; byte rec;
  511. inline macrinfo(){prevstep=&_lazy; rec=1; stack=0; nvars=0;};
  512. inline val&operator[](int i){return stack[(i>?0)<?(nvars-1)];};
  513. inline ~macrinfo(){delete stack;};};
  514. extern macrinfo basemi,*mi;
  515. #define play (mi!=&basemi)
  516. /*-----*/
  517. inline byte keysdown(){_ax=0x0200; int16(); return _ax&255;}
  518. enum {k_rshift=1, k_lshift=2, k_ctrl=4, k_alt=8, /* these 4 pressed */
  519.   k_scrlock=16, k_numlock=32, k_capslock=64, k_insert=128, /* these 4 toggle */
  520.   k_break=14 /* alt & ctrl & left shift */ };
  521. extern int loseip();
  522. inline int Breakin(){_ax=0x0200; int16(); return (_ax&14)==14?loseip():0;}
  523. /*-----*/
  524. extern subr*keep[]; extern char keyseqc[];
  525. extern val keyseq; /* work space */
  526. extern char rec; /* whether to record this step */
  527. /*-----*/
  528. extern void Insert(int N,byte c);
  529. extern void Replace(int N,int D,val T1,val T2,char *pt,int ask,int word);
  530. extern void search(int N,int D,val T1,char*prompt,int back=0,int word=0);
  531. extern void incrsearch(int N,int D,char*pt,int back=0);
  532. extern void readescno(short c);
  533. extern void readaltno(short c);
  534. extern byte &bufmode(int i,buffer*BB=0);
  535. /*-----*/
  536. extern char**dispmode[];
  537. extern void(*cf[])(int,byte);
  538. extern subr*cff[];
  539. /*-----*/
  540. extern void insert_(int N,byte c);
  541. extern void overlay_(int N,byte c);
  542. extern void nomove_(int N,byte c);
  543. extern void forallkeys(void Subr(val*),int L=1,keyarray&K=keys);
  544. extern void moan_if_no_help(val*f);
  545. extern void prbuffer(buffer*C);
  546. extern void print_subr(val*f);
  547. extern Subr*namedsubr(val name);
  548. extern val*getk(val arg,char*prompt=0);
  549. /*-----*/
  550. extern void translate(buffer*BB);
  551. extern buffer*buf_named(val name);
  552. extern int findbuf_new(val&name,int read=1);
  553. extern buffer*findbuf(val name);
  554. extern region thisword(int N=1);
  555. extern region thispara();
  556. extern void casechange(int N,line*L,int b,int e);
  557. /*-----*/
  558. extern val eosentchars; extern byte ccc; extern char rept;
  559. extern Subr subrname[]; extern Func funcname[];
  560. /*-----*/
  561. Kf(_idle); Kf(accentedletters); Kf(alt0); Kf(alt1); Kf(alt2); Kf(alt3);
  562. Kf(alt4); Kf(alt5); Kf(alt6); Kf(alt7); Kf(alt8); Kf(alt9); Kf(altminus);
  563. Kf(backspace); Kf(beginmacro); Kf(bindkeybuf); Kf(bindkeymacro);
  564. Kf(bindkeysubr); Kf(buffer_); Kf(buffermenu); Kf(calldos); Kf(callsubr);
  565. Kf(capitalize); Kf(casemode); Kf(cbrackets); Kf(cccmode); Kf(cchrstr);
  566. Kf(checkhelp); Kf(checkspelling); Kf(copybufmodes); Kf(copydir); Kf(copykill);
  567. Kf(copytext); Kf(cstrchr); Kf(delblanklines); Kf(delbuf); Kf(delet);
  568. Kf(deletewhite); Kf(dis_play); Kf(displayhex); Kf(emptyappendix); Kf(endmacro);
  569. Kf(esc0); Kf(esc1); Kf(esc2); Kf(esc3); Kf(esc4); Kf(esc5); Kf(esc6); Kf(esc7);
  570. Kf(esc8); Kf(esc9); Kf(escminus); Kf(expandtabs); Kf(finalcr); Kf(findb);
  571. Kf(findf); Kf(findwordb); Kf(findwordf); Kf(finish); Kf(formatinsetregion);
  572. Kf(formatpara); Kf(formatregion); Kf(getappendix); Kf(godown); Kf(godownpart);
  573. Kf(goleft); Kf(goright); Kf(gotobof); Kf(gotobol); Kf(gotocol); Kf(gotodir);
  574. Kf(gotoeof); Kf(gotoeol); Kf(gotoline); Kf(gotonbuf); Kf(goup); Kf(gouppart);
  575. Kf(go_to); Kf(help); Kf(If); Kf(incrfindb); Kf(incrfindf); Kf(insert);
  576. Kf(insertfile); Kf(insertspaces); Kf(kill_to_eol); Kf(killregion); Kf(killsent);
  577. Kf(killwordb); Kf(killwordf); Kf(leaveonewhite); Kf(linefeed); Kf(literalchar);
  578. Kf(longlinesmode); Kf(lwcaseregion); Kf(lwcasewords); Kf(macromenu);
  579. Kf(maketabs); Kf(markbof); Kf(markeof); Kf(menu); Kf(mergefile); Kf(modemenu);
  580. Kf(mouse_mode); Kf(mouse_move); Kf(movetext); Kf(namemacro); Kf(newline);
  581. Kf(nextwindow); Kf(nofinalcr); Kf(nomove); Kf(obey); Kf(onewindow);
  582. Kf(openfile); Kf(openline); Kf(overlay); Kf(overlaymode); Kf(page_down);
  583. Kf(page_up); Kf(popmark); Kf(prbindings); Kf(prbuffers); Kf(prevwindow);
  584. Kf(prkeynames); Kf(prkeys); Kf(prmacro); Kf(prmacros); Kf(prsubrnames);
  585. Kf(pushmark); Kf(putappendix); Kf(readmacros); Kf(refresh_display); Kf(remmark);
  586. Kf(renamebuffer); Kf(repeat); Kf(repl); Kf(replask); Kf(replword);
  587. Kf(replwordask); Kf(replyank); Kf(restorebuf); Kf(savebuffer); Kf(setmark);
  588. Kf(setolddot); Kf(setrightmargin); Kf(setsortcol); Kf(showinfo); Kf(showregion);
  589. Kf(skipafterwordmode); Kf(skipparab); Kf(skipparaf); Kf(skipsentb);
  590. Kf(skipsentf); Kf(skipwordb); Kf(skipwordf); Kf(sortlines); Kf(splitwindow);
  591. Kf(swopmark); Kf(tabmode); Kf(tabulate); Kf(times4); Kf(twiddle);
  592. Kf(twiddlelines); Kf(twiddlewords); Kf(twodmode); Kf(unbindkey);
  593. Kf(upcaseregion); Kf(upcasewords); Kf(version); Kf(whoa); Kf(wrapmode);
  594. Kf(writebuffer); Kf(yank);
  595. /*-----*/
  596. fN(_allocate); fN(_andthen); fN(_divide); fN(_minus); fN(_neg); fN(_plus);
  597. fN(_eq); fN(_ne); fN(_ge); fN(_le); fN(_gt); fN(_lt);
  598. fN(_same); fN(_times); fN(currentbuffer); fN(keyseq_);
  599. /*-----*/
  600. extern void start_an_arg();
  601. extern val&getkeyseq(val P);
  602. inline val&getkeyseq(char*P) {return getkeyseq(val(P,strlen(P)));}
  603. /*-----*/
  604. extern byte esc_alt[26];
  605. extern char*getstringhelp[];
  606. extern char*rsvword[],**info;
  607. /*-----*/
  608. extern void out_of_store();
  609. extern void showmoan();
  610. extern int fileexists(char*);
  611. extern Subr*subrmenu(char*s);
  612. extern Func*funcmenu(char*s);
  613. extern byte drive();
  614. extern void getcurrentdir(char c,char*s);
  615. extern void refreshscreen();
  616. extern buffer*buffer_menu(char*prompt);
  617. extern void filefromdirmenu(val&Dir,char*prompt,char*at=0);
  618. extern int attrib(char*file);
  619. extern buffer*get_file(val&T,char*prompt);
  620. extern unsigned long filesize(char*name);
  621. extern void bitpack(char*s,char*t,int n);
  622. extern void bitexp(char*s,char*t,int n);
  623. extern void bitcopy(char*s,char*t,int n);
  624. extern int charfrommenu();
  625. extern void del_every(val f,keyarray&ka);
  626. extern void del_every(val f,val&m);
  627. extern void del_every(val f,macstep*M);
  628. extern void del_every(val f);
  629. extern void wr(char*s);
  630. extern int display_op_uses();
  631. /*-----*/
  632. #define totab(i) (((i)|7)+1) /* next tab position after i */
  633. #define sptotab(i) (7-((i)&7))
  634.     /* how many spaces (not inclusive) from i to next tab position after i */
  635. /*-----*/
  636. extern char*pr(char*B,char*F0,...);
  637. extern char*pa(char*B,char*F0,...);
  638. extern void pf(int f,char*F0,...);
  639. extern void pb(char*F0,...);
  640. extern void ps(char*F0,...);
  641. extern void p_r(char*S,char*F0,...);
  642. extern char*pr_(char*S,char*F0,int*args);
  643. extern char**readtext(char*file);
  644. extern val named(val name);
  645. extern int byteq(char*a,char*b,int n);
  646. extern int check_spelling(char*ws,int wl);
  647. extern int&appendixsize;
  648. extern char*dictname;
  649. extern short*screendump();
  650. extern void screenrestore(short*s);
  651. extern int deletebuffer(buffer*C);
  652. extern void*myalloc(int i);
  653. extern void counterchange(uns short&x);
  654. extern int linewhere(mark M);
  655. extern macro*macro_menu();
  656. extern int bottommenu(
  657.   char*prompt,int nrb,char*codes,char**names,int L=8,int defolt=0);
  658. /*-----*//* MOUSE */
  659. #define Regs _go32_dpmi_registers
  660. extern void event(Regs*R);
  661. extern int int86dpmi(int intno);
  662. extern Regs R;
  663. #define Int int86dpmi
  664. /*-----*/
  665. class mousestate {public: int x,y,xe,ye; char visible,mc,bd;
  666.     inline mousestate(){};
  667.     void operator=(Mouse&);};
  668. /*-----*/
  669. class Mouse {public: int x,y,xe,ye,ldx,ldy,mdx,mdy,rdx,rdy;
  670. char nbuttons,buttons,visible,handlerInstalled,mc,bd;
  671. void show();
  672. void hide();
  673. void read();
  674. void move(int Y,int X);
  675. inline Mouse(){};
  676. void setup();
  677. void operator=(mousestate&);
  678. void settrap(uns int,void (*func)(Regs *));
  679. void range(int ye,int xe);
  680. ~Mouse();};
  681. /*-----*/
  682. extern Mouse Jerry; extern int oldmx,oldmy; enum{LB=1,MB=4,RB=2};
  683. /*-----*/
  684. /* extern int debug;
  685. inline void prdeb(char*s) {write(debug,s,strlen(s));}
  686. #define DEBUG debug=open("t$debug",0x0802)
  687. #define GUBED close(debug) */
  688. //#include <stdio.h>
  689. //extern FILE*debug;
  690. //inline void prdeb(char*s) {fprintf(debug,"%s",s);}
  691. //#define DEBUG debug=fopen("t$debug","a")
  692. //#define GUBED fclose(debug)
  693.  
  694. //#define longjmp(x,y) ({DEBUG; fprintf(debug,"line %1d of "__FILE__":\
  695. // longjmp("#x","#y");\n",__LINE__); GUBED; longjmp(x,y);})
  696. //#define setjmp(x) ({DEBUG; int miaow; fprintf(debug,"line %1d of "__FILE__":\
  697. // setjmp("#x"); set up\n",__LINE__);\
  698. // if(miaow=setjmp(x)) fprintf(debug,"line %1d of "__FILE__":\
  699. // setjmp("#x"); jumped to\n",__LINE__); GUBED; miaow;})
  700.